﻿using System;

namespace IslandUnit
{
    /// <summary>
    /// Contains available actions to <see cref="StubItemSetup&lt;TDependency, TResult&gt;"/>.
    /// These actions are available when the stub returns one object.
    /// </summary>
    /// <typeparam name="TDependency">The type of the dependency.</typeparam>
    /// <typeparam name="TResult">The type of object returned.</typeparam>
    public class StubItemAction<TDependency, TResult> : StubAction<TDependency>, IHideObjectMembers where TDependency : class
    {
        private readonly TResult _result;

        /// <summary>
        /// Initializes a new instance of the <see cref="StubItemAction&lt;TDependency, TResult&gt;"/> class.
        /// </summary>
        /// <param name="dependency">The <see cref="Dependency&lt;TDependency&gt;"/> of your dependency.</param>
        /// <param name="result"></param>
        public StubItemAction(Dependency<TDependency> dependency, TResult result)
        {
            this.Dependency = dependency;
            this._result = result;
        }

        /// <summary>
        /// Allow to configure the result using lambda expressions.
        /// Can be chained.
        /// </summary>
        /// <param name="expression">The lambda expression to invoke.</param>
        /// <returns>An <see cref="StubItemAction&lt;TDependency, TResult&gt;"/>, where you can chain the configuration expressions.</returns>
        public StubItemAction<TDependency, TResult> With(Action<TResult> expression)
        {
            expression.Invoke(this._result);

            return this;
        }
    }
}